package com.cws.frame.interceptor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.cws.sys.Constant;
import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

public class Post implements Interceptor {
	
	public void intercept(ActionInvocation ai) {

		BufferedReader in = null;
		try {
			in = new BufferedReader(new InputStreamReader(ai.getController().getRequest().getInputStream()));
			String line;
			StringBuffer sb = new StringBuffer();

			while ((line = in.readLine()) != null) {
				sb.append(line);
			}
			
			//System.out.println(sb.toString());
			
			ai.getController().setAttr(Constant.REQ_BODY, sb.toString());

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		ai.invoke();

	}
}